<extend name="Index/index" />

<block name="include">
    <script src="__PUBLIC__/Admin/js/pintuer.js"></script>
   
</block>
<block name="main">
 <div class="panel admin-panel">
  <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 单页信息</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="<{:U('AddArticle')}>">      
      <div class="form-group">
        <div class="label">
          <label>标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input" name="title" value="" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
	        <div class="label">
	          <label>父级分类</label>
	        </div>
	        <div class="field">
	            <select id="sort1" name="categoryid" class="input w50">
	                <option  value="">请选择分类</option>
	                <option  value="0">一级分类</option>
	                <foreach name="data" item="vo">
	                    <option   value=<{$vo.id}>><{$vo.name}></option>
	                </foreach>   
	            </select>
	        	<script>
	            $(function(){
	                $('#sort1').change(function(){
	                    var categoryid =$('#sort1').val();
	                    if(categoryid!=''&&categoryid!=0){
	                        $.ajax({
	                            url:"<{:U('Category/GetCategoryByPid')}>",
	                            data:"pid="+categoryid,
	                            type:'get',
	                            success:function(msg){
	                                var len= msg.length;
	                                if(len>0){
	                                	$('#sort1').attr('name','categoryid');
	                                	$('#sort1').siblings('select').remove();
	                                    $('#sort1').parent().append('<select id="sort2" class="input w50"> </select>');
	                                    $('#sort2').append('<option  value="">请选择分类</option>');
	                                    for (var i = 0; i < len; i++) {
	                                        $('#sort2').append('<option  value='+msg[i]['id']+'>'+msg[i]['name']+'</option>');
	                                    }
	                                    $('#sort2').change(function(){
	                                    		$('#sort2').attr('name','categoryid');
	                                            var val =$('#sort2').val();
	                                            if(val != ''){
	                                            	$.ajax({
							                            url:"<{:U('Category/GetCategoryByPid')}>",
							                            data:"pid="+val,
							                            type:'get',
							                            success:function(msg){
							                            	var len= msg.length;
	                                						if(len>0){
	                                							$('#sort2').next('select').remove();
	                                							$('#sort2').parent().append('<select id="sort3" class="input w50"> </select>');
	                                							$('#sort3').append('<option  value="">请选择分类</option>');
	                                							for (var i = 0; i < len; i++) {
							                                        $('#sort3').append('<option  value='+msg[i]['id']+'>'+msg[i]['name']+'</option>');
							                                    }
							                                    $('#sort3').change(function(){
							                                    	var val =$('#sort3').val();alert(val);
							                                    	if(val !=''){
							                                    		$('#sort2').removeAttr('name');
	                                                					$('#sort3').attr('name','categoryid');
	                                                				}else{
		                                                				$('#sort3').removeAttr('name');
		                                                				$('#sort2').attr('name','categoryid');
	                                                			}
							                                    	
							                                    });
							                                    
	                                						}else{
	                                							$('#sort3').removeAttr('name');
	                                                			$('#sort2').attr('name','categoryid');
	                                							$('#sort2').next('select').remove();
	                                						}
							                            }
							                        });
	                                                $('#sort1').removeAttr('name');
	                                                $('#sort2').attr('name','categoryid'); 
	                                            }else{
	                                                $('#sort2').removeAttr('name');
	                                                $('#sort1').attr('name','categoryid');
	                                                 $('#sort2').next('select').remove();
	                                            }
	                                    });
	                                }else{
	                                	$('#sort1').attr('name','categoryid');
	                                    $('#sort1').siblings('select').remove();
	                                    // $('#hidden').remove();
	                                }
	                            }
	                        });
	                    }else{
	                    	$('#sort1').attr('name','categoryid');
	                        $('#sort1').siblings('select').remove();
	                    }                         
	                }); 
	            })
	            </script>
	        </div>
	    </div>
      <div class="form-group">
        <div class="label">
          <label>内容：</label>
        </div>
        <div class="field">
          <textarea name="content"></textarea>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
    
</block>

